package com.starblink.search.result.ui.fragment

import android.os.Bundle
import android.view.View
import androidx.annotation.CallSuper
import androidx.viewbinding.ViewBinding
import com.starblink.android.basic.base.fragment.BaseTVMLazyLoadingFragment
import com.starblink.search.search.ui.SearchTVMActivity

/**
 * 搜索结果Loading特殊处理
 *  Create by yuanl at 2023/10/28
 **/
abstract class BaseSearchFragment<T : ViewBinding, VM : BaseSearchVM>: BaseTVMLazyLoadingFragment<T, VM>() {

    override fun isDefaultShowLoading(): Boolean = false

    override fun transformRootView(view: View): View {
        return super.transformRootView(view)
    }

    override fun showStateLoading() {
        //super.showStateLoading()
        viewModel.showActivityLoading()
    }

    override fun showStateSuccess() {
        super.showStateSuccess()
        viewModel.hideActivityLoading()
    }

    @CallSuper
    override fun onLazyInitData() {
        viewModel.showActivityLoading()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewModel.activityLoadingLD.observe(this.viewLifecycleOwner) {
            if (it) {
                (activity as? SearchTVMActivity)?.showDialogLoading()
            } else {
                (activity as? SearchTVMActivity)?.dismissDialogLoading()
            }
        }
    }



}